<?php

namespace app\stores\model\order;


use app\common\model\CommonModel;


use app\beautiful\model\order\GoodsOrderItemModel;
use app\common\model\ShopModel;
use think\facade\Db;

class ReasonModel extends CommonModel{

    protected  $name = 'beautiful_reason';

    protected  $pk   = 'reason_id';



    public static function onBeforeInsert($model)
    {
        $model->set("add_time", date('Y-m-d H:i:s'));
        $model->set("add_ip", request()->ip());
    }

    public static function list($where,$order,$page=1,$limit=10){
        $query = Db::name('beautiful_reason')
            ->where(['is_delete'=>0])
            ->when(isset($where['type']),function ($query) use ($where){
                $query->where('type','=',$where['type']);
            })
            ->when(isset($where['shop_id']),function ($query) use ($where){
                $query->where('shop_id','=',$where['shop_id']);
            })
            ->when(isset($where['reason_ids']),function ($query) use ($where){
                $query->whereIn('reason_id',$where['reason_ids']);
            })
            ->field("*");
        $query=$query->order($order)->limit($limit)->page($page);
        $list=$query->select()->toArray();
        return $list;
    }
}



